# Copyright (c) 2009 Peter Houghton 
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

# WATIR GRID
# Build file for WatirGrid

require 'rake'
require 'rake/gempackagetask'
require 'rubygems'


GEMSPEC_FILE='watirgrid.gemspec'

task :default => :unittest
  
task :build => :unittest do
  puts "Building!"
  
  require 'rubygems'
  require 'rubygems/gem_runner'

  # Call GEM to build .gem package file.
  Gem::GemRunner.new.run ['build' , GEMSPEC_FILE]
  
end # build the gem file

# Run unit tests, Exit if they fail.
task :unittest do 
  require 'test/unit'
  require 'test/unit/testsuite'
  require 'test/unit/ui/console/testrunner'
  require 'test/grid_map_tests'
  require 'test/grid_http_server_tests'

   class WatirGridTests
     def self.suite
       suite = Test::Unit::TestSuite.new
       suite << Grid_map_tests.suite
       suite << Grid_http_server_tests.suite
       return suite
     end
   end
  unit_results = Test::Unit::UI::Console::TestRunner.run(WatirGridTests)
  
  # Read the global value, containg the test results.
  unless unit_results.passed?
    puts "Tests failed, Exiting!"
    exit 2
  else 
    puts "Tests OK!"
  end # end else
  
end # run unittest


